package fr.mauclair.domogeek.persist;

import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Named;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Named("entityLoader")
public class EntityLoader {

	private static final Logger LOG = LoggerFactory.getLogger(EntityLoader.class);

	@Inject
	private CommandeRepository commande;

	@Inject
	private JobRepository jobRepo;

	@Inject
	private JobActionRepository jobActionRepo;

	@PostConstruct
	private void load() {

		System.out.println("###############################################################");
		System.out.println("###############################################################");
		System.out.println("###############################################################");
		System.out.println("###############################################################");
		System.out.println("###############################################################");
		System.out.println("###############################################################");

		Commande commande1 = commande.save(new Commande("commande1"));
		Commande commande2 = commande.save(new Commande("commande2"));

		LOG.info("  **** Saved Commande1: " + commande1);

		Job job = new Job();
		job.setName("job1");
		jobRepo.save(job);

		JobAction jobAction = new JobAction();
		jobAction.setName("jobaction1");
		jobAction.setJob(job);
//		jobActionRepo.save(jobAction);

		job.addJobActions(jobAction);
//
//		job = jobRepo.save(job);

		jobAction = new JobAction();
		jobAction.setName("jobaction2");
		jobAction.setJob(job);
		job.addJobActions(jobAction);
		jobRepo.save(job);

	}

}
